#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
using namespace std;

int main()
{
  //cout << "hello world" << endl;
  umask(0);
  if(mkfifo("./fifo", 0666))
  {
    cout << "mkfifo failed" << endl;
    return -1;
  }

  int fd = open("./fifo", O_RDONLY);
  if(fd < 0)
  {
    cerr << "open failed" << endl;
  }

  char buffer[1024] =  {0};
  ssize_t s=  read(fd, buffer, sizeof(buffer) - 1);
  if(s <0)
  {
    cout << "read failed" << endl;
  }
  else if(s == 0)
  {
    cout << "client quit" << endl;
  }
  else 
  {
    cout << "server read success:" << buffer << endl;
  }
}
